﻿
namespace CleverCMS.Core.Infrastructure
{
    using System.Web.Hosting;
    using System.Web.Routing;

    using StructureMap;

    using MvcSiteMapProvider.Loader;
    using MvcSiteMapProvider.Web.Mvc;
    using MvcSiteMapProvider.Xml;

    public class SitemapRegistration
    {
        public static void RegisterAll(RouteCollection routes)
        {
            var container = new Container();
            // Setup configuration of DI (required)
            container.Configure(r => r.AddRegistry<MvcSiteMapProviderRegistry>());

            // Setup global sitemap loader (required)
            MvcSiteMapProvider.SiteMaps.Loader = container.GetInstance<ISiteMapLoader>();

            // Check all configured .sitemap files to ensure they follow the XSD for MvcSiteMapProvider (optional)
            var validator = container.GetInstance<ISiteMapXmlValidator>();
            validator.ValidateXml(HostingEnvironment.MapPath("~/Mvc.sitemap"));

            var validatorAdmin = container.GetInstance<ISiteMapXmlValidator>();
            validatorAdmin.ValidateXml(HostingEnvironment.MapPath("~/Mvc.admin.sitemap"));

            // Register the Sitemaps routes for search engines (optional)
            XmlSiteMapController.RegisterRoutes(routes);

        }
    }
}
